package shellstation;

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JFrame;

public class SalesView implements ActionListener {

    private JFrame frame;

    private boolean watcher= false;
    private int yesNo;
    
    private JMenuBar menuBar;

    private JMenu file;

    private JMenuItem mainMenu;
    private JMenuItem logOut;

    private JPanel bluePanel;
    private JPanel panel;
    private JPanel panel2;

    private JLabel salesText;
    private JLabel salesIconLabel;

    private JButton addReceiptButton;
    private JButton viewProdPerfReportButton;
    private JButton backButton;
    private JButton editReceiptButton;

    private Icon salesIcon;
    private Icon backIcon;

    private Color yellow = new Color(255, 218, 63);
    private Color gray = new Color(222,222,222);
    private Color red = new Color(226, 0, 0);
    private Color blue = new Color(62, 142, 169);

    public void SalesView(){

        salesIcon = new ImageIcon(getClass().getResource("image/bigSalesIcon.gif"));
        backIcon = new ImageIcon(getClass().getResource("image/back.png"));

        salesIconLabel = new JLabel();
        salesIconLabel.setIcon(salesIcon);
        salesIconLabel.setBounds(130, 100, 300, 300);

        menuBar= new JMenuBar();
        file= new JMenu("File");
        mainMenu= new JMenuItem("Main Menu");
        logOut= new JMenuItem("Log Out");

        mainMenu.addActionListener(this);

        menuBar.add(file);
        file.add(mainMenu);
        file.add(logOut);

        frame = new JFrame("Shell Station - Inventroy Sales System");
        frame.setSize(750, 450);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setResizable(true);
        frame.setJMenuBar(menuBar);

        salesText = new JLabel("Sales Facilities");
        salesText.setFont(new Font("Hobo Std", Font.BOLD, 28));
        salesText.setBounds(70, 20, 225, 50);

        addReceiptButton = new JButton("Add Receipt");
        addReceiptButton.setBackground(gray);
        addReceiptButton.setBounds(18, 25, 250, 75);
        addReceiptButton.setFont(new Font("Arial", Font.BOLD, 20));
        addReceiptButton.addActionListener(this);

        viewProdPerfReportButton = new JButton("Product Performance");
        viewProdPerfReportButton.setBackground(gray);
        viewProdPerfReportButton.setBounds(18, 215, 250, 75);
        viewProdPerfReportButton.setFont(new Font("Arial", Font.BOLD, 20));
        viewProdPerfReportButton.addActionListener(this);

        editReceiptButton= new JButton("Edit Receipt");
        editReceiptButton.setBackground(gray);
        editReceiptButton.setBounds(18, 115, 250, 75);
        editReceiptButton.setFont(new Font("Arial", Font.BOLD, 20));
        editReceiptButton.addActionListener(this);

        backButton= new JButton("Go Back", backIcon);
        backButton.setBackground(gray);
        backButton.setBounds(18, 315, 250, 75);
        backButton.setFont(new Font("Arial", Font.BOLD, 20));
        backButton.addActionListener(this);

        bluePanel= new JPanel(null);
        bluePanel.setBounds(55, 25, 350, 75);
        bluePanel.setBackground(blue);

        bluePanel.add(salesText);

        panel = new JPanel(null);
        panel.setBackground(red);

        panel2= new JPanel(null);
        panel2.setBounds(300, 0, 750, 424);
        panel2.setBackground(yellow);

        panel2.add(bluePanel);
        panel2.add(salesIconLabel);

        panel.add(panel2);
        panel.add(addReceiptButton);
        panel.add(viewProdPerfReportButton);
        panel.add(editReceiptButton);
        panel.add(backButton);

        frame.add(panel);

    }
    public void actionPerformed(ActionEvent e){
        if(e.getSource() == addReceiptButton){
           
           
           if(watcher == true){
               yesNo =JOptionPane.showConfirmDialog(null, "Cancel Transaction?", null, JOptionPane.YES_NO_OPTION);
           }
           
           
           if(yesNo == JOptionPane.YES_OPTION || watcher == false){
           
           watcher = true;
           
           panel2.removeAll();
           panel2.repaint();

           ReceiptView r = new ReceiptView();
           r.ReceiptView();

           panel2.add(r.getreceiptNumberH());
           panel2.add(r.getreceiptNumberT());
           panel2.add(r.getlistOfProductsH());
           panel2.add(r.getscrollpane());
           panel2.add(r.getline2());
           panel2.add(r.getproductQuantity());
           panel2.add(r.getSize());
           panel2.add(r.getproductSize());
           panel2.add(r.getQuantity());
           panel2.add(r.getaddProductButton());
           panel2.add(r.getSubmitButton());
           panel2.add(r.getremoveProductButton());
           panel2.add(r.getscrollpane2());
           panel2.add(r.getSearchButton());
           r.setpanel(panel2);

           panel2.repaint();
           panel2.revalidate();
            }
        }

        else if(e.getSource() == viewProdPerfReportButton){

           if(watcher == true ){
                yesNo =JOptionPane.showConfirmDialog(null, "Cancel Transaction?", null, JOptionPane.YES_NO_OPTION);
            }
           if(yesNo == JOptionPane.YES_OPTION){
           watcher = true;
           
           panel2.removeAll();
           panel2.repaint();


           PerformanceView pv = new PerformanceView();
           pv.PerformanceView();
       
           panel2.add(pv.getFrom());
           panel2.add(pv.getScrollPane());
           panel2.add(pv.getTo());
           panel2.add(pv.getday2());
           panel2.add(pv.getday());
           panel2.add(pv.getmonth());
           panel2.add(pv.getmonth2());
           panel2.add(pv.getyear());
           panel2.add(pv.getyear2());
           panel2.add(pv.getday2());
           panel2.add(pv.getday());
           panel2.add(pv.getmonth());
           panel2.add(pv.getGoButton());

           panel2.repaint();
           panel2.revalidate();
            }
        }

        else if(e.getSource() == backButton){

            frame.dispose();
            MainMenu m= new MainMenu();
            m.MainMenu();

            
        }

        else if(e.getSource() == mainMenu){

            frame.dispose();
            MainMenu m= new MainMenu();
            m.MainMenu();
        }

        else if(e.getSource() == editReceiptButton){

            

            if(watcher == true ){
                yesNo =JOptionPane.showConfirmDialog(null, "Cancel Transaction?", null, JOptionPane.YES_NO_OPTION);
            }
           
            
            if( yesNo == JOptionPane.YES_OPTION || watcher == false ){

            watcher = true;
            panel2.removeAll();
            panel2.repaint();

            editReceiptView ed= new editReceiptView();
            ed.editReceiptView();

            panel2.add(ed.getday());
            panel2.add(ed.getmonth());
            panel2.add(ed.getreceiptNo());
            panel2.add(ed.getscrollPane());
            panel2.add(ed.getyear());
            panel2.add(ed.getreceiptNumberL());
            panel2.add(ed.getmonthLabel());
            panel2.add(ed.getdayLabel());
            panel2.add(ed.getyearLabel());
            panel2.add(ed.getUpdate());
            panel2.add(ed.getfind());
            ed.setPanel(panel2);

            panel2.repaint();
            panel2.revalidate();
            }
        }
    }

    
}

